<?php
/**
 * Inquirers Controller
 *
 * PHP version 5
 *
 * @category Controller
 * @package  Croogo
 * @version  1.0
 * @author   Tran Van Dung <dungtv@ic-t.info>
 * @license  http://www.opensource.org/licenses/mit-license.php The MIT License
 * @link     http://www.croogo.org
 */
class InquirersController extends AppController {
/**
 * Controller name
 *
 * @var string
 * @access public
 */
    public $name = 'Inquirers';
/**
 * Models used by the Controller
 *
 * @var array
 * @access public
 */
    public $uses = array('Inquirer');
/**
 * Helpers used by the Controller
 *
 * @var array
 * @access public
 */
    public $helpers = array('Text');

    protected $paginate = array(
        'limit' => 10,
        );

/**
 * Before executing controller actions
 *
 * @return void
 * @access public
 */
    public function beforeFilter() {
        parent::beforeFilter();

        if ($this->action == 'add' || $this->action == 'edit' || $this->action == 'admin_add' || $this->action == 'admin_edit') {
            $this->Security->validatePost = false;
        }
    }

/**
 * Admin index
 *
 * @return void
 * @access public
 */
    public function admin_index() {
        $this->set('title_for_layout', __('PRODUCER LIST'));

        $this->Inquirer->recursive = 0;
        $this->paginate['Inquirer']['order'] = 'Inquirer.name ASC';
        $this->set('inquirers', $this->paginate());
    }

/**
 * Admin add
 *
 * @return void
 * @access public
 */
    public function admin_add() {
        $this->set('title_for_layout', __('PRODUCER DETAIL'));

        if (!empty($this->request->data)) {
            
            $this->Inquirer->create();
            if ($this->Inquirer->save($this->request->data)) {
                //$this->Session->setFlash(__('The Inquirer has been saved'), 'default', array('class' => 'success'));

                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Inquirer could not be saved. Please, try again.'), 'default', array('class' => 'error'));
            } 
        } 
    }

/**
 * Admin edit
 *
 * @param int $id 
 * @return void
 * @access public
 */
    public function admin_edit($id = null) {
        $this->set('title_for_layout', __('PRODUCER DETAIL'));

        if (!$id && empty($this->request->data)) {
            $this->Session->setFlash(__('Invalid Inquirer'), 'default', array('class' => 'error'));
            $this->redirect(array('action'=>'index'));
        }
        if (!empty($this->request->data)) {
            if ($this->Inquirer->save($this->request->data)) {
                //$this->Session->setFlash(__('The Inquirer has been saved'), 'default', array('class' => 'success'));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Inquirer could not be saved. Please, try again.'), 'default', array('class' => 'error'));
            }
        }
        if (empty($this->request->data)) {
            $this->request->data = $this->Inquirer->read(null, $id);
        }
    }

/**
 * Admin delete
 *
 * @param int $id 
 * @return void
 * @access public
 */
    public function admin_delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for Inquirer'), 'default', array('class' => 'error'));
            $this->redirect(array('action'=>'index'));
        }

        $inquirer = $this->Inquirer->find('first', array(
            'conditions' => array(
                'id' => $id,
            ),
        ));
        if (isset($inquirer['Inquirer'])) {
            if ($this->Inquirer->delete($id)) {
                //$this->Session->setFlash(__('Inquirer deleted'), 'default', array('class' => 'success'));
                $this->redirect(array('action'=>'index'));
            }
        } else {
            $this->Session->setFlash(__('Invalid id for Inquirer'), 'default', array('class' => 'error'));
            $this->redirect(array('action'=>'index'));
        }
    }

}
?>